package controllers;

import java.util.ArrayList;
import java.util.List;

import models.Answer;
import models.Candidate;
import models.Question;
import models.User;
import play.mvc.Controller;
import play.mvc.With;


public class Answers extends Controller{
public static void ChooseAnswer(long id){
	Candidate cand=Candidate.findById(id);
	Question quest=cand.question;
	User user=Security.getConnected();
	Candidate candidate=null;
	for(Answer a:user.answers){
		if(a.question.id==quest.id){
			 candidate=cand;
			
		}
		
	}
	if(candidate==null){
		Answer ans=new Answer(cand);
		ans.save();
		cand.save();
		if(user.answers==null){
			user.answers=new ArrayList<Answer>();
		}
		user.answers.add(ans);
		user.save();
		ans.voter=user;
		user.save();
		ans.save();
		
	}
	
	render(cand,candidate);
	
}
}
